package com.sy.cloud.guess.service.impl;

import com.gok.pay.wx.WXPayConfig;
import com.sy.cloud.guess.config.WxPayConfig;
import com.sy.cloud.guess.model.WxConfig;
import com.sy.cloud.guess.service.IWxConfigService;
import com.sy.common.service.IBaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Created by mac on 2017-12-28.
 */
@Service
@Slf4j
public class WxConfigService implements IWxConfigService {
    @Resource
    private IBaseService baseService;

    /**
     * 获得支付公众号配置
     * @return
     */
    @Override
    @Transactional
    public WXPayConfig getWxPayConfig() {
        WxPayConfig config = new WxPayConfig();
        String hql = "From WxConfig where status = 1";
        WxConfig wxConfig = baseService.queryObject(hql, WxConfig.class);
        if(wxConfig == null) {
            log.error("WxConfig is null");
            return config;
        }
        config.setApiSecret(wxConfig.getApiSecret());
        config.setAppId(wxConfig.getAppId());
        config.setAppSecret(wxConfig.getAppSecret());
        config.setMchId( wxConfig.getMchId() );
        config.setDomain(wxConfig.getWxDomain());
        config.setMchId(wxConfig.getMchId());
        config.setKey( wxConfig.getApiSecret() );

        return config;
    }
}
